package im.engure.common.registery;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * ”主机注册信息“，这里暂时存放在本地，JVM级别
 * <p>
 * 存储结构
 * =========
 * {
 * interfaceName1 : [(ip1,port1), (ip2,port2),,,],
 * interfaceName1 : [(ip3,port3), (ip4,port4),,,],
 * }
 */
public class LocalHostsRegistry {

    private static final Map<String, List<URL>> SERVICE_HOSTS = new HashMap<>();

    public static void registerHost(String interfaceName, URL url) {
        List<URL> list = SERVICE_HOSTS.getOrDefault(interfaceName, new LinkedList<>());
        list.add(url);
        SERVICE_HOSTS.put(interfaceName, list);
    }

    public static List<URL> getHosts(String interfaceName) {
        return SERVICE_HOSTS.getOrDefault(interfaceName, null);
    }

}
